import router from './index.js'

import store from '@/store/index.js'

const vipList = ['/setting']
router.beforeEach((to, from, next) => {
  const token = store.state.tokenInfo.token
  // 没有token要去有权限的页面
  if (!token && vipList.includes(to.path)) {
    // 跳转到登录页带上参数登录后回到原位置
    next('/login?backto=' + encodeURIComponent(to.fullPath))
    // 有token要去登录页去主页
  } else if (token && to.path === '/login') {
    next('/')
  } else {
    next()
  }
})
export default router
